<?php

$in = "";
$str = "";
for($i=1;$i<$argc;$i++){
    echo $argv[$i] . PHP_EOL;
    $str .= file_get_contents($argv[$i]);
}

$kong = array(" ","　","\t","\n","\r",PHP_EOL);
$str = str_replace($kong,'',$str);

/**
 * 匹配中文括号里的词语
 */
//preg_match_all('/\（([\x{4e00}-\x{9fa5}a-zA-Z0-9]+)\）/',$str, $matches);

//preg_match_all( '|(?mi-Us)\\（([\\x{4e00}-\\x{9fa5}]+)\\）|', $str, $matches) ;

$pattern = '/（(.*)）/isU';

preg_match_all($pattern, $str, $matches);

$str = implode("",$matches[1]);
//var_dump($str);
//var_dump($matches[1]);
file_put_contents('二年级上册-词语.txt',$str);
echo mb_strlen($str);


/**
 * @param $str
 * @param int $length
 * @return array|array[]|false|string[]
 * 把字符串拆分为数组，支持中文等其它多字节语言
 */
function str_split_unicode($str, $length = 1) {
    $tmp = preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY);
    if ($length > 1) {
        $chunks = array_chunk($tmp, $length);
        foreach ($chunks as $i => $chunk) {
            $chunks[$i] = join('', (array) $chunk);
        }
        $tmp = $chunks;
    }
    return $tmp;
}